<?php

namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;

use  App\Models\Comment;

use Illuminate\Support\Facades\DB;
use Cache;
use Validator;
use Carbon\Carbon;

class CommentController extends Controller
{
    public function create(Request $request)
    {
        $input = Input::only('currUserName','snsId');
        $validator = Validator::make($input, [        
            'snsId' => 'required',
            'currUserName' => 'required',
        ]);
        if ($validator->fails()) {
            return $this->returnError([],401,'参数错误');
        }
        // $exist = Comment::where('snsId',$input['snsId'])->where('uid',$input['currUserName'])->first();
        // if($exist){
        //     $exist->likeNum = $input['likeNum']??'';
        //     $exist->commentsNum = $input['commentsNum']??'';
        //     $exist->likesJson = $input['likesJson']??'';
        //     $exist->commentsJson = $input['commentsJson']??'';
        //     $exist->likes = $input['likes']??'';
        //     $exist->likeFlag = $input['likeFlag']??'';
        //     $exist->comments = $input['comments']??'';
        //     $exist->save();
        // }else{
            $data = Input::all();
            $data['uid'] = $data['currUserName'];
            Comment::create($data);
        // }
        return $this->returnOk();
    }
}

        






